#include <bits/stdc++.h>

using namespace std;

string a,b;
string rulea[10] , ruleb[10];
int cnt;
int lastnodecnt;
int main()
{
    cin>>a>>b;
    int n = 0;
    while(!cin.eof()){
        cin>>rulea[n]>>ruleb[n];
        n++;
    }
    queue <string> q;
    q.push(a);
    while(!q.empty()){
        int nodecnt = 0;
        for(int i=0 ;i<n ;i++){
            int la = q.front().length();
            string temp = q.front();
            for(int j =0 ; j<la;j++ ){
                for(int k = j;k<la;k++){
                    if(temp.compare(j,k-j+1,rulea[i])==0){
                        nodecnt++;
                        string news = temp;
                        news.replace(j,k-j+1,ruleb[i]);
                        cout<<nodecnt<<" "<<news<<endl;
                        if(news == b) {cout<<nodecnt; return 0;}
                        q.push(news);
                    }
                }
            }
        }
        q.pop();
    }
    cout<<"NO ANSWER!";
    return 0;
}
